
#include <BStream>
#include <BStyle>
#include "member_BGroupBox.h"

using namespace BWE;

member_BGroupBox::member_BGroupBox(BGroupBox* groupBox)
{
	boss = groupBox;
	align = Align_Center;
	foldable = false;
	checkable = false;
	folded = false;
	checked = false;
	lineWidth = 2;
}
member_BGroupBox::~member_BGroupBox()
{

}

void member_BGroupBox::freshRects()
{
	int border = boss->border();
	int width = boss->width();
	int height = boss->height();

	int top = boss->perchs().top();
	int left = boss->perchs().left() / 2;
	int right = boss->perchs().right() / 2;
	int bottom = boss->perchs().bottom() / 2;

	if (folded)
	{
		points[0].set(border + left, border + top / 2);
		points[1].set(width - border - right, border + top / 2);
	}
	else
	{
		points[0].set(border + left, border + top / 2);
		points[1].set(border + left, height - border - bottom);
		points[2].set(width - border - right, height - border - bottom);
		points[3].set(width - border - right, border + top / 2);
	}

	const BStyle* style = boss->realStyle();
	if (style)
		style->trans(boss->title(), t_title);
	else
		t_title.clear();

	BSize textSize;
	const BFont* font = boss->font();
	if (font)
	{
		if (t_title.size())
			textSize = font->textSize(t_title);
		else
			textSize = font->textSize(boss->title());
	}

	BRect titleRect = boss->rect(Part_Title);

	BSize realImageSize = imageSize;
	if (realImageSize.width() < textSize.width())
		realImageSize.width() = textSize.width();
	if (realImageSize.height() < textSize.height())
		realImageSize.height() = textSize.height();
	realImageSize.wrap(titleRect.size());

	imageRect = titleRect.align(align, realImageSize);
	textRect = imageRect.align(Align_Center, textSize);
}
